<template>
  <div class="box">
    <div class="header">
      <div class="back" @click="back()"></div>
      <p v-show = "changeData === 0">全部订单</p>
      <p v-show = "changeData === 1">待付款</p>
      <p v-show = "changeData === 2">待收货</p>
      <p v-show = "changeData === 3">待评价</p>
    </div>
    <ul class="nav">
      <li @click="change(index)" v-for="(item,index) in changes" :key="index" :class='index==changeData?"redborder":""'>{{item}}</li>
    </ul>
    <div class="data" v-show = "haveData == true">
      <div class="havedata" v-show = "changeData === 0 && haveData == true" v-for="(item,index) in allOrderData">  <!-- 全部订单-->
        <p class="ordernum">订单编号：{{item.gid}}</p>
        <div class="orderlist">
          <img :src="item.image" alt="">
          <p class="title">{{item.title}}</p>
        </div>
        <p class="price">实付金额：{{item.price}} <button @click="delOrders1(index)">取消订单</button></p>
      </div>
      <div class="havedata" v-show = "changeData === 1 && haveData == true" v-for="(item,index) in pendingPaymentData"> <!-- 待付款-->
        <p class="ordernum">订单编号：{{item.gid}}</p>
        <div class="orderlist">
          <img :src="item.image" alt="">
          <p class="title">{{item.title}}</p>
        </div>
        <p class="price">实付金额：{{item.price}} <button @click="delOrders2(index)">取消订单</button></p>
      </div>
      <div class="havedata" v-show = "changeData === 2 && haveData == true" v-for="(item,index) in goodsReceivedData">   <!-- 待收货-->
        <p class="ordernum">订单编号：{{item.gid}}</p>
        <div class="orderlist">
          <img :src="item.image" alt="">
          <p class="title">{{item.title}}</p>
        </div>
        <p class="price">实付金额：{{item.price}} <button @click="delOrders3(index)">取消订单</button></p>
      </div>
      <div class="havedata" v-show = "changeData === 3 && haveData == true" v-for="(item,index) in evaluatedData">       <!-- 待评价-->
        <p class="ordernum">订单编号：{{item.gid}}</p>
        <div class="orderlist">
          <img :src="item.image" alt="">
          <p class="title">{{item.title}}</p>
        </div>
        <p class="price">实付金额：{{item.price}} <button @click="delOrders4(index)">取消订单</button></p>
      </div>
    </div>
    <p class="haventdata" v-show = "changeData === 0 && haveData == false">没有相关数据！</p>
    <p class="haventdata" v-show = "changeData === 1 && haveData == false">没有相关数据！</p>
    <p class="haventdata" v-show = "changeData === 2 && haveData == false">没有相关数据！</p>
    <p class="haventdata" v-show = "changeData === 3 && haveData == false">没有相关数据！</p>
  </div>
</template>

<script>
  import axios from 'axios'
  export default  {
    mounted() {
      var that = this;
      axios.get('http://vueshop.glbuys.com/api/user/myorder/index?uid=696443691& status=all&token=1ec949a15fb709370f&page=1').then(function(res){
        if(res.data.data.goods !== ''){
              that.allOrderData = res.data.data[0].goods;
              that.haveData = true;
            }else{
              that.haveData = false;
            }
      })
    },
    data() {
      return {
        changeData:0,
        changes:["全部订单","待付款","待收货","待评价"],
        isActive:false,
        allOrderData:[],        //全部订单数据
        pendingPaymentData:[],  //待付款数据
        goodsReceivedData:[],   //待收货数据
        evaluatedData:[],       //待评价数据
        haveData:true  
      }
    },
    methods: {
      change(type){
        var that = this;
        this.changeData = type;
        if(type==0){
          axios.get('http://vueshop.glbuys.com/api/user/myorder/index?uid=696443691& status=all&token=1ec949a15fb709370f&page=1').then(function(res){
            if(res.data.data.goods !== ''){
              that.allOrderData = res.data.data[0].goods;
              that.haveData = true;
            }else{
              that.haveData = false;
            }
          })
        }else if(type==1){
          axios.get('http://vueshop.glbuys.com/api/user/myorder/index?uid=696443691& status=0&token=1ec949a15fb709370f&page=1').then(function(res){
            if(res.data.data.goods !== ''){
              that.pendingPaymentData = res.data.data[0].goods;
              that.haveData = true;
            }else{
              that.haveData = false;
            }
          })
        }else if(type==2){
          axios.get('http://vueshop.glbuys.com/api/user/myorder/index?uid=696443691& status=1&token=1ec949a15fb709370f&page=1').then(function(res){
            if(res.data.data.good !== ''){
              that.goodsReceivedData = res.data.data[0].goods;
              that.haveData = true;
            }else{
              that.haveData = false;
            }
          })
        }else{
          axios.get('http://vueshop.glbuys.com/api/user/myorder/reviewOrder?uid=696443691&page=1&token=1ec949a15fb709370f').then(function(res){
            if(res.data.data.good !== ''){
              that.evaluatedData = res.data.data[0].goods;
              that.haveData = true;
            }else{
              that.haveData = false;
            }
          })
        }
      },
      delOrders1(type){
        this.allOrderData.splice(type,1)
      },
      delOrders2(type){
        this.pendingPaymentData.splice(type,1)
      },
      delOrders3(type){
        this.goodsReceivedData.splice(type,1)
      },
      delOrders4(type){
        this.evaluatedData.splice(type,1)
      },
      back(){
        this.$router.back(-1)
      }
    },
    computed: {

    }
}
</script>

<style scoped>
  .header{
    width: 100%;
    height: 1.01rem;
    line-height: 1.01rem;
    text-align: center;
    border-bottom: 0.02rem solid #f7f7f7;
    box-sizing: border-box;
    font-size: 0.32rem;
    display: flex;
    justify-content: flex-start;
  }
  .header p{
    width: 72%;
  }
  .back{
    width: 1rem;
    height: 100%;
    background-image: url(/static/Back_LSQ.png);
    background-repeat: no-repeat;
    background-size: 100%;
    background-position: 0 50%;
  }
  .nav{
    display: flex;
    justify-content: space-around;
    width: 100%;
    height: 0.78rem;
    border-bottom: 0.01rem solid #e2e2e2;
    box-sizing: border-box;
  }
  .nav li{
    list-style: none;
    text-align: center;
    display: block;
    height: 0.78rem;
    width: 25%; 
    padding-top: 0.24rem; 
    font-size: 0.29rem; 
    box-sizing: border-box;                                              
  }
  .haventdata{
    width: 100%;
    height: 1.42rem;
    line-height: 1.42rem;
    border-top: 0.02rem solid #dbdbdb;
    border-bottom: 0.01rem solid #f6f6f6;
    background: #efefef;
    text-align: center;
    font-size: 0.32rem;
  }
  .redborder{
    border-bottom: 0.01rem solid red;
  }
  .data{
    width: 100%;
    padding-top: 0.23rem;
    padding-bottom: 0.23rem;
    background: #efefef;
  }
  .data .havedata{
    width: 100%;
    background: #ffffff;
  }
  .data .havedata .ordernum{
    width: 100%;
    height: 0.8rem;
    line-height: 0.8rem;
    font-size: 0.27rem;
  }
  .data .havedata .orderlist{
    width: 100%;
    height: 1.64rem;
    border-top: 2px solid #efefef;
    border-bottom: 2px solid #efefef;
    display: flex;
    text-align: left;
    justify-content: space-between;
    align-items: center;
  }
  .data .havedata .orderlist img{
    width: 1.22rem;
    height: 1.22rem;
    margin-left: 0.2rem;
    margin-right: 0.4rem;
  }
  .data .havedata .orderlist .title{
    margin-right: 0.2rem;
    font-size: 0.26rem;
  }
  .data .havedata .price{
    width: 100%;
    height: 0.82rem;
    line-height: 0.82rem;
    font-size: 0.27rem;
    border-bottom: 2px solid #f17f1f;
    box-sizing: border-box;
    display: flex;
    padding-left: 0.22rem;
    justify-content: space-between;
    align-items: center;
  }
  .data .havedata .price button{
    width: 1.2rem;
    height: 0.48rem;
    border: 2px solid #f15353;
    border-radius: 5px;
    font-size: 0.23rem;
    background: #ffffff;
    margin-right: 0.2rem; 
  }
</style>
